//
//  XQHomeNavBarView.m
//  JoinPeso
//
//  Created by 小琦 on 2024/11/19.
//

#import "XQHomeNavBarView.h"
#import <SDWebImage/UIButton+WebCache.h>

@interface XQHomeNavBarView()
@property (nonatomic,strong) UILabel *nameLabel;
@property (nonatomic,strong) UIButton *kefuBtn;
@end

@implementation XQHomeNavBarView

- (instancetype)init
{
    self = [super init];
    if (self) {
        [self makeUI];
        [self makeConstraints];
    }
    return self;
}

- (void)makeUI {
    [self addSubview:self.nameLabel];
    [self addSubview:self.kefuBtn];
}

- (void)makeConstraints {
    [self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        (void)make.centerY;
        make.left.equalTo(@24);
    }];
    [self.kefuBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.equalTo(@24);
        make.height.equalTo(@24);
        make.right.equalTo(@-12);
        (void)make.centerY;
    }];
}

#pragma mark - setter

- (void)setLogo:(NSString *)logo {
    [self.kefuBtn sd_setImageWithURL:[NSURL URLWithString:logo] forState:UIControlStateNormal placeholderImage:[UIImage imageNamed:@"kefu"]];
}

#pragma mark - paivte

- (void)kefuClick {
    if (self.customerHandle) {
        self.customerHandle();
    }
}

#pragma mark - lazy

- (UILabel *)nameLabel {
    if (!_nameLabel) {
        _nameLabel = [[UILabel alloc] init];
        _nameLabel.textColor = [UIColor colorWithHexString:@"#0E1D31"];
        _nameLabel.font = [UIFont boldSystemFontOfSize:18];
        _nameLabel.text = @"Hello,user!";
    }
    return _nameLabel;
}

- (UIButton *)kefuBtn {
    if (!_kefuBtn) {
        _kefuBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_kefuBtn addTarget:self action:@selector(kefuClick) forControlEvents:UIControlEventTouchUpInside];
    }
    return _kefuBtn;
}

@end
